import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

import java.awt.*;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class BrowsePage extends JMenuItem implements Command{
	
    private JEditorPane display;
    private JTextField addressBar;
    private String userText;
   
    public BrowsePage(JEditorPane panel, JTextField addressBar)
    {
        this.display=panel;
        this.addressBar=addressBar;
    }
    
    private void loadPage(String userText) {
        try {
            display.setPage(userText);
            addressBar.setText(userText);
        } catch (Exception ex) {}
    }
    
    public void execute()
    {
        //display.setBackground(Color.WHITE);

        
        Thread fir = new Thread()
        {
                public void run()
                { 
                	display = new JEditorPane();
                    display.setEditable(false);
                    display.addHyperlinkListener(new HyperlinkListener() {

                    public void hyperlinkUpdate(HyperlinkEvent hevt) {
                            if (hevt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                                loadPage(hevt.getURL().toString());
                            }
                        }
                    });
                    
                    add(new JScrollPane(display), BorderLayout.CENTER);
                    setSize(500, 300);
                    setVisible(true);
   
                }
        };
        fir.start();  
        
    } 
}
